/* 
 * File:   squareMatrix.cpp
 * Author: Stephen Durfey
 * Class : CS335
 * 
 * Description: this file defines the class public member functions
 * of the class 'squareMatrix'. 
 *
 * Created on September 14, 2008, 10:48 PM
 */

#include "squareMatrix.h"


#include <iostream>

using namespace std;

//Default constructor: intializes the entire array to zero

squareMatrix::squareMatrix()
{
    for(int row = 0; row < MAX_SIZE; row++)
    {
        for(int col = 0; col < MAX_SIZE; col++)
            matrix[row][col] = 0;
    }
}

//sets the rows and columns of the array, up to 'emptySize' equal to zero

void squareMatrix::MakeEmpty(int emptySize)
{
    for(int row = 0; row < emptySize; row++)
    {
        for(int col = 0; col < emptySize; col++)
            matrix[row][col] = 0;
    }
}

//stores the particular value in the proper array index

void squareMatrix::StoreValue(int row, int col, int value)
{
    matrix[row][col] = value;
}

//return sthe value of the index at the specified [row][col]. This function
//is needed in 'Add()' and 'Subtract()'

int squareMatrix::getIndexVal(int row, int col)
{
    return matrix[row][col];
}

//accept's a squareMatrix object as a parameter, sums 2 matrices (calling object
//and parameter object) together and returns the sum.

int squareMatrix::addMatrix(squareMatrix matrix2)
{
    int total = 0;
    
    for(int row = 0; row < MAX_SIZE; row++)
    {
        for(int col = 0; col < MAX_SIZE; col++)
            total += matrix[row][col] + matrix2.getIndexVal(row, col);            
    }
    
    return total;
}

//Accepts a squareMatrix object as a parameter and subtracts it from the calling object

void squareMatrix::Subtract(squareMatrix obj2)
{
    for(int row = 0; row < MAX_SIZE; row++)
    {
        for(int col = 0; col < MAX_SIZE; col++)
            matrix[row][col] -= obj2.getIndexVal(row, col);
    }
}

//Accepts a squareMatrix object as a parameter and copies that object's index 
//values into the calling object's indice's

void squareMatrix::copyMatrix(squareMatrix obj2)
{
    for(int row = 0; row < MAX_SIZE; row++)
    {
        for(int col = 0; col < MAX_SIZE; col++)
            matrix[row][col] = obj2.getIndexVal(row, col);
    }
}

